// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "../ciscompresslib/ciscompresslib.h"
#include "../cpplib/FileTool.h"
#include <iostream>

bool _assure_path_exist1(const char* szPath)
{
	string s  = szPath;
	char*  p  = (char*)s.c_str();

	while (true)
	{
		char* t1 = strchr(p,'\\');
		char* t2 = strchr(p,'/');

		char* t = t1 < t2 ? (t1==NULL?t2:t1) : (t2==NULL?t1:t2);

		if ( t != NULL )
		{
			*t = 0;
			p  = t;
		}

		if ( _mkdir(s.c_str()) < 0 && errno != EEXIST && s.at(1) != ':')
		{
			return false;
		}

		if ( t == NULL )
		{
			break;
		}
		else
		{
			*p = '\\';
			p++;
			if ( *p == 0 )
			{
				break;
			}
		}
	}

	return true;
}

bool _assure_path_exist2(const char* szPath)
{
	string s  = szPath;
	char*  p  = (char*)s.c_str();

	while (true)
	{
		char* t1 = strchr(p,'\\');
		char* t2 = strchr(p,'/');

		char * t = NULL;
		if (t1<=t2 && t1 != NULL)
		{
			t = t1;
		}
		if (t2<t1 && t2 != NULL)
		{
			t = t2;
		}

		if ( t != NULL )
		{
			*t = 0;
			p  = t;
		}

		if ( _mkdir(s.c_str()) < 0 && errno != EEXIST && s.at(1) != ':')
		{
			return false;
		}

		if ( t == NULL )
		{
			break;
		}
		else
		{
			*p = '\\';
			p++;
			if ( *p == 0 )
			{
				break;
			}
		}
	}

	return true;
}

int _tmain(int argc, _TCHAR* argv[])
{
	assure_path_exist("./asdf\\asdf/d/d\\\\das//asd");
	assure_path_exist("d:/asdf\\asdf/d/d\\das//asd");
	assure_path_exist("c:/asdf\\asdf/d/d\\das//asd");
	//FILE * fp = fopen("test.ciz", "w");
	//if (fp == NULL)
	//{
	//	fprintf(stdout,"failed\n");
	//	return 0;
	//}
	//
	//list<pair<string,string>> ll;
	//ll.push_back(pair<string,string>("c:\\kk/sample.setup","D:\\mod_ciz\\bigfile\\sample.setup"));
	//ll.push_back(pair<string,string>("d:/bb/sampleclient_1.0.1.2.ciz","D:\\mod_ciz\\sampleclient_1.0.1.2.ciz"));
	//ll.push_back(pair<string,string>("d:/bb\\zlibd.lib","D:\\cis\\trunk\\trunk\\code\\lib\\zlibd.lib"));
	//
	//unsigned int re = compress_files(fp,ll, NULL,NULL); //compress_dir(fp, "kk", NULL, NULL);
	//
	//fprintf(stdout,"ok\n");
	//fclose(fp);

	//fp = fopen("test.ciz", "r");
	//decompress_file(fp, "yy", NULL, NULL);
	//fclose(fp);

	return 0;
}

